<?php
/*
author name: shravani
created date: 14-07-2013
*/
error_reporting( E_ERROR | E_USER_ERROR );
if(isset($_POST['action']) && $_POST['action'] == "add")
{
	//Get the file extention
$userfile_name = $_FILES['upfrm']['name'];
$userfile_extn = explode(".", strtolower($_FILES['upfrm']['name']));

 $file_name = "tmp/".date('his').'_'.$_FILES['upfrm']['name']; //xml file saving format
 	
	if($userfile_extn[1]=="xml")
	{
		if(move_uploaded_file($_FILES["upfrm"]['tmp_name'], $file_name)) 
		{
		  if(simplexml_load_file($file_name))
           {
	       header("location:filterfrm.php?name=".$file_name);
		   exit;
           }else{
	       header("location:errfrm.php?msgs=invalid");
		   exit;
          }	
		}
	} 
	else
	{	
		header("location:upfrm.php?msg=fail");
		exit;
     }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Upload Xml File</title>
</head>
<body>
<form name="uploadfrm" method="post" enctype="multipart/form-data">
  <input type="hidden" id="action" name="action" value="add" />
  <table width="100%" border="0" align="center" cellpadding="2" cellspacing="0">
    <?php if((isset($msg))&&($msg=="fail")){?>
    <tr>
      <td colspan="3" align="center" class="Red10b">Please Upload Only Xml Files.</td>
    </tr>
    <?php }?>
    <tr>
      <td align="right"><b><span>Upload a Xml Form:</span></b></td>
      <td align="left">&nbsp;</td>
    </tr>
    <tr>
      <td align="right"><b><span class="Red10b">*</span> File:</b></td>
      <td align="left"><input name="upfrm" type="file" id="upfrm"  value="" size="30" />
        &nbsp;</td>
    </tr>
    <tr>
      <td align="right">&nbsp;</td>
      <td align="left"><input type="submit" name="submit" value="Submit"/>
        &nbsp;</td>
    </tr>
  </table>
</form>
</body>
</html>